package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResCategory;
import com.ruoyi.system.service.IResCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐馆分类Controller
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/system/rescategory")
public class ResCategoryController extends BaseController
{
    @Autowired
    private IResCategoryService resCategoryService;

    /**
     * 查询餐馆分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:rescategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResCategory resCategory)
    {
        startPage();
        List<ResCategory> list = resCategoryService.selectResCategoryList(resCategory);
        return getDataTable(list);
    }

    /**
     * 导出餐馆分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:rescategory:export')")
    @Log(title = "餐馆分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResCategory resCategory)
    {
        List<ResCategory> list = resCategoryService.selectResCategoryList(resCategory);
        ExcelUtil<ResCategory> util = new ExcelUtil<ResCategory>(ResCategory.class);
        util.exportExcel(response, list, "餐馆分类数据");
    }

    /**
     * 获取餐馆分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rescategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(resCategoryService.selectResCategoryByCategoryId(categoryId));
    }

    /**
     * 新增餐馆分类
     */
    @PreAuthorize("@ss.hasPermi('system:rescategory:add')")
    @Log(title = "餐馆分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResCategory resCategory)
    {
        return toAjax(resCategoryService.insertResCategory(resCategory));
    }

    /**
     * 修改餐馆分类
     */
    @PreAuthorize("@ss.hasPermi('system:rescategory:edit')")
    @Log(title = "餐馆分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResCategory resCategory)
    {
        return toAjax(resCategoryService.updateResCategory(resCategory));
    }

    /**
     * 删除餐馆分类
     */
    @PreAuthorize("@ss.hasPermi('system:rescategory:remove')")
    @Log(title = "餐馆分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(resCategoryService.deleteResCategoryByCategoryIds(categoryIds));
    }

    @GetMapping("/selectResCategoryListVant")
    public AjaxResult selectResCategoryListVant(){
        return success(resCategoryService.selectResCategoryListVant());
    }
}
